package com.cloudpivot.receivales;

import com.alibaba.fastjson.JSONObject;

import com.cloudpivot.receivales.ding.robot.controller.RobotController;
import com.cloudpivot.receivales.ding.robot.service.RobotServiceImpl;
import com.cloudpivot.receivales.ding.robot.util.SpringContextUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.*;

@SpringBootTest
class CloudpivotApplicationForRobot {

    @Autowired
    private RobotServiceImpl robotService;

    @Autowired
    private RobotController robotController;


    @Test
    public void pushMsg() {
        List<String> lists = new ArrayList<>();
        lists.add("020722623423157211");
        List<String> list = new ArrayList<>();
        list.add("问题一");
        list.add("问题二");
        list.add("问题三");
        list.add("问题4");
        list.add("问题5");
        list.add("问题6");
        JSONObject jsonObject = robotService.modeCreate(list);
        System.out.println(JSONObject.toJSONString(jsonObject));

//        robotService.answerCardMuti(lists, jsonObject);
    }

    @Test
    public void pushCard() {
//        robotService.productCardPush(Arrays.asList("020722623423157211"),"试剂");

        Map<String, String> map = new HashMap<>();
        map.put("test1","productCardPush");


        try {
            Class ro = robotService.getClass();
//            Constructor con =  ro.getConstructor();
//            RobotServiceImpl impl = (RobotServiceImpl) con.newInstance();
            Method method=ro.getMethod("productCardPush",List.class,String.class);

            method.invoke(SpringContextUtil.getBean("robotServiceImpl"),Arrays.asList("020722623423157211"), "试剂");
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

    }

    @Test
    public void pushCard2() {
        JSONObject req = new JSONObject();
        req.put("title", "回复");
//        req.put("text", "我可以回答  \n  ***  \n  * <font color=\"#e91e63\">我爱北京天安门我爱北京天安门我爱北京天安门我爱北京天安门我爱北京天安门我爱北京天安门</font>  \n  * [文档连接](https://alidocs.dingtalk.com/i/nodes/Gl6Pm2Db8D3m2mKEim729GwBJxLq0Ee4?utm_scene=team_space)");
        req.put("text", "我可以回答  \n  ***  \n  * 问题一  \n  >* 问题二  \n");
        robotService.answerMsg(Arrays.asList("020722623423157211"),req);
    }

    @Test
    public void pushCard3() {
//        String msg="<a href='dingtalk://dingtalkclient/page/link?url=https%3A%2F%2Falidocs.dingtalk.com%2Fi%2Fnodes%2Fm9bN7RYPWdlgNgB1iAgw9Z3ZWZd1wyK0%3Futm_scene%3Dteam_space&pc_slide=true'>侧边连打开</a>";
        String msg="<a href='https://alidocs.dingtalk.com/i/nodes/m9bN7RYPWdlgNgB1iAgw9Z3ZWZd1wyK0?utm_scene=team_space'>测试打开</a>";
//        robotService.productDefaultPush(Arrays.asList("020722623423157211"),msg);
    }

    @Test
    public void pushGroup() {
        String msgkey = "sampleMarkdown";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("title", "问题回复");
        jsonObject.put("text", "@020722623423157211 AT人员效果");
        String openid = "cidjjWoadtgB/3iQObydImVyA==";
//        robotService.groupPushService(openid, msgkey, jsonObject);
    }





}
